import { maintainCheckStatus, maintainCheckStatusKeyArray } from '@/consts/maintaincheck.consts';
import { apiService } from '../../api/apiService';
import { ref } from 'vue';
import { getPointInspectionResultParams, postUpdateDeviceCheckRecord } from '@/api/server';
import { showSuccess } from '../../util/MessageDeal';
export const deviceCheckStatisticFormat = (statistic) => {
    return maintainCheckStatusKeyArray.map((child) => {
        const number = statistic[child];
        const { color, text } = maintainCheckStatus[child];
        return `<span style="color:${color}">${number}项${text} </span>`;
    }).join(' ');
};

export const DeviceCheckSetup = () => {
    const device_check_result_options = ref([]);

    const getDeviceCheckResultOptions = () => {
        apiService({
            api: getPointInspectionResultParams,
            param: {},
            success: (data) => {
                device_check_result_options.value = data.value;
            }
        });
    };

    const updateDeviceCheckRecord = (param, callback) => {
        apiService({
            api: postUpdateDeviceCheckRecord,
            param: { ...param },
            success: (data) => {
                showSuccess('保存维保记录成功');
                callback && callback();
            }
        });
    };

    return {
        device_check_result_options, updateDeviceCheckRecord, getDeviceCheckResultOptions
    };
};
